package edu.gatech.oad.ui;
import java.awt.CardLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;

import edu.gatech.oad.schedule.CheckedInPanel;
import edu.gatech.oad.user.LoginPanel;
import edu.gatech.oad.user.User;
import edu.gatech.oad.user.UserEditPanel;
/**
 * Class for the user interface, allows for the 
 * login and user panels to be switched seamlessly. 
 * @author Joey Slater
 * @version 1.00
 *
 */
public class MainPanel extends JPanel{
	private static final long serialVersionUID = 1L;
	private LoginPanel loginPanel;
	private UserPanel userPanel;
	private UserEditPanel registerPanel;
	private JFrame frame;
	private static final String LOGINPANEL = "Login Panel";
	private static final String USERPANEL = "User Panel";
	private static final String REGISTERPANEL = "Register Panel";
	private CardLayout cardLayout = new CardLayout(); //Allows for switching
	/**
	 * Constructor class for the main panel
	 * @param frame the program's frame
	 */
	public MainPanel(JFrame frame){
		this.setLayout(cardLayout); //sets the layout 
		this.loginPanel= new LoginPanel(this);
		this.userPanel = new UserPanel(null); //creates the beginning user panel
		this.registerPanel = new UserEditPanel(true);
		this.add(loginPanel, LOGINPANEL); //adds both panel
		this.add(userPanel, USERPANEL); 
		this.add(registerPanel, REGISTERPANEL);
		this.frame = frame;
	}
	
	/**
	 * Switching to the specific user's class 
	 * @param user the user logging in
	 */
	public void switchToUserPanel(User user){
		userPanel.setUserForPanel(user); //sets the user
		frame.setJMenuBar(new MenuBar(this, userPanel)); //makes visible the menu bar
		cardLayout.show(this, USERPANEL); //switches the layout
	}
	
	/**
	 * Visual representation of the log out
	 */
	public void switchToLoginPanel(){
		userPanel.setUserForPanel(null); //sets the information back to null;
		userPanel.removeAllTabs();
		frame.setSize(loginPanel.getLoginPanelDimension());
		cardLayout.show(this, LOGINPANEL); //switches to login panel
	}
	
	public void switchToRegisterPanel(){
		cardLayout.show(this, REGISTERPANEL); //switches to login panel
	}
}
